package com.tysong.qq.patterns.impl;

import com.alibaba.fastjson.JSONObject;
import com.tysong.qq.patterns.Strategy;
import com.tysong.qq.utils.Compared;
import love.forte.simbot.api.message.events.GroupMsg;
import love.forte.simbot.api.sender.MsgSender;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 策略模式获取打卡名单类
 * @Project: qq
 * @Author: Sunday
 * @Create: 2021-09-01 20:53
 **/

@Component("getDaka")
public class OperationGetCheckList implements Strategy {

    private static final String[] INITIAL_DATA_LIST = {"表情包老铁", "张三", "李四", "王五"};

    @Override
    public void doOperation(GroupMsg msg, MsgSender sender, String groupNumber, List<String> listName) {

        List<String> checkIsList = new ArrayList<>(Arrays.asList(INITIAL_DATA_LIST));
        List<String> collect = listName.stream().distinct().collect(Collectors.toList());
        List<String> noCheckIsList = new ArrayList<>(collect);
        String string = "";
        for (String str : noCheckIsList) {
            String[] strings = str.split(" ");
            string = strings[0];
        }
        List<String> finallyList = new ArrayList<>(Collections.singletonList(string));
        List<String> different = Compared.getDifferent(checkIsList, finallyList);
        // collect.forEach(s -> sender.SENDER.sendGroupMsg(groupNumber, s));
        String nameOrder = "应打卡" + INITIAL_DATA_LIST.length + "人,实际打卡" + collect.size() + "人；剩余未打：" + (INITIAL_DATA_LIST.length - collect.size());
        StringBuilder sb = new StringBuilder();
        sb.append("未打卡名为：");
        if (ObjectUtils.isNotEmpty(different)) {
            for (String diff : different) {
                sb.append(diff).append(",");
            }
        }
        sb.deleteCharAt(sb.length() - 1);
        sender.SENDER.sendGroupMsg(groupNumber, nameOrder);
        sender.SENDER.sendGroupMsg(groupNumber, sb.toString());
    }

    @Override
    public void neteaseCloudMusic(MsgSender sender, String groupNumber, String keyword) throws Exception {
    }
}
